<template>
    <div>
        <div class="headerSty" style="margin: 20px 0 10px;">
            <div class="headerLeftSty">
                <div class="navSty"></div>
                <div class="textSty">低值易耗材料清单</div>
            </div>
            <el-button type="primary" @click="addList">下载</el-button>
        </div>
        <div>
            <el-table :data="billData" style="width: 100%">
                <el-table-column type="index" label="序号" width="180"/>
                <el-table-column prop="materialName" label="材料设备名称" width="180"/>
                <el-table-column prop="specificationModel" label="规格型号" width="180"/>
                <el-table-column prop="price" label="单价（元）"/>
                <el-table-column prop="unit" label="单位"/>
                <el-table-column prop="remark" label="备注"/>
            </el-table>
        </div>

        <div class="headerSty" style="margin: 20px 0 10px;">
            <div class="headerLeftSty">
                <div class="navSty"></div>
                <div class="textSty">项目消防维保初检情况及处理建议</div>
            </div>
            <el-button type="primary" @click="addAdvList">下载</el-button>
        </div>
        <div>
            <el-table :data="adviseData" style="width: 100%">
                <el-table-column type="index" label="序号" width="180"/>
                <el-table-column prop="question" label="问题" width="180"/>
                <el-table-column prop="processingScheme" label="处理方案" width="180"/>
                <el-table-column prop="hazardLevel" label="危险等级"/>
                <el-table-column prop="demand" label="需求"/>
                <el-table-column prop="estimatedCost" label="预估人工费用"/>
            </el-table>
        </div>
    </div>
</template>
<script>

import {
    getBillList, getAdviseList,
    adviseExport, billExport
} from "@/api/contract/contractOrg";
import { blobValidate } from "@/utils/ruoyi";
import { saveAs } from 'file-saver'
export default {
    props: {
        dataForm: {
            type: Object,
            default: {},
        }
    },
    data() {
        return {
            form: {},
            // 表单校验
            rules: {},
            billData: [],
            adviseData: [],
        }
    },
    created() {
        this.getList()
    },
    methods: {
        getList() {
            getBillList(this.dataForm.projectSaveDTO.id).then(res => {
                this.billData = res.data
            })
            getAdviseList(this.dataForm.projectSaveDTO.id).then(res => {
                this.adviseData = res.data
            })
        },
        addList() {
            billExport({ id: this.dataForm.projectSaveDTO.id }).then(async data => {
                const isBlob = blobValidate(data);
                const filename = '低值易耗材料清单';
                if (isBlob) {
                    saveAs(data.data, filename)
                } else {
                    const resText = await data.text();
                    const rspObj = JSON.parse(resText);
                    const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
                    this.$modal.msgError(errMsg);
                }
                this.$modal.loading("正在上传图片，请稍候...");
            })
        },
        addAdvList() {
            adviseExport({ id: this.dataForm.projectSaveDTO.id }).then(async data => {
                const isBlob = blobValidate(data);
                // const filename = decodeURIComponent(data.filename);
                const filename = '项目消防维保初检情况及处理建议';
                if (isBlob) {
                    saveAs(data.data, filename)
                } else {
                    const resText = await data.text();
                    const rspObj = JSON.parse(resText);
                    const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
                    this.$modal.msgError(errMsg);
                }
            })
        },
    }
}
</script>

<style lang="scss" scoped>
.headerSty {
    display: flex;
    justify-content: space-between;
    width: 97%;
}

.headerLeftSty {
    display: flex;
    align-items: center;
}

.navSty {
    height: 15px;
    width: 5px;
    background: rgb(90, 156, 248);
}

.textSty {
    margin-left: 8px;
    font-size: 16px;
    font-weight: 700;
}
</style>